<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="会员金币充值/消费记录" prop="hyUserGoldId">
									<el-input v-model="form.hyUserGoldId" placeholder="请输入会员金币充值/消费记录" clearable></el-input>
								</el-form-item>
								<el-form-item label="会员id" prop="hyUserId">
									<el-input v-model="form.hyUserId" placeholder="请输入会员id" clearable></el-input>
								</el-form-item>
								<el-form-item label="流水号" prop="cwAccountBalanceIsId">
									<el-input v-model="form.cwAccountBalanceIsId" placeholder="请输入流水号" clearable></el-input>
								</el-form-item>
								<el-form-item label="类型1充值 2消费 3奖励 4扣除 5消费退还" prop="doType">
									<el-input v-model="form.doType" placeholder="请输入类型1充值 2消费 3奖励 4扣除 5消费退还" clearable></el-input>
								</el-form-item>
								<el-form-item label="值 消费是负数" prop="value">
									<el-input v-model="form.value" placeholder="请输入值 消费是负数" clearable></el-input>
								</el-form-item>
								<el-form-item label="记录时间" prop="doTime">
									<el-input v-model="form.doTime" placeholder="请输入记录时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="说明" prop="msg">
									<el-input v-model="form.msg" placeholder="请输入说明" clearable></el-input>
								</el-form-item>
								<el-form-item label="记录人,对应sys_user业务员id,现场充值等场景有用" prop="recSysUserId">
									<el-input v-model="form.recSysUserId" placeholder="请输入记录人,对应sys_user业务员id,现场充值等场景有用" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '充值记录'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					hyUserGoldId: "",
					hyUserId: "",
					cwAccountBalanceIsId: "",
					doType: "",
					value: "",
					doTime: "",
					msg: "",
					recSysUserId: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.hygl.hyUserGold.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.hyUserGoldId = data.hyUserGoldId;
				this.form.hyUserId = data.hyUserId;
				this.form.cwAccountBalanceIsId = data.cwAccountBalanceIsId;
				this.form.doType = data.doType;
				this.form.value = data.value;
				this.form.doTime = data.doTime;
				this.form.msg = data.msg;
				this.form.recSysUserId = data.recSysUserId;
			}
		}
	}
</script>
<style>
</style>
